package com.qf.dao.impl;

import com.qf.dao.TeamDao;

import com.qf.pojo.Team;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class TeamDaoImpl implements TeamDao {
    QueryRunner queryRunner= new QueryRunner(DataSourceUtil.getDataSource());
    @Override
    public List<Team> selectAllTeam() {
        String sql="select * from team ";
        try {
            return queryRunner.query(sql,new BeanListHandler<>(Team.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Team findTeamById(int teamId) {
        String sql = "select * from team_type1 where team_type1_id=?";
        try {
            return queryRunner.query(sql,new BeanHandler<>(Team.class),teamId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }


}
